﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using BusinessLogicLibrary;
using entities;

namespace ServiceLibrary
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class ExternalService : IExternalService
    {
        private readonly CustomerModule _customer = new CustomerModule();
        private readonly SearchModule _search = new SearchModule();

        #region "CUSTOMER Management"

        public bool CusEmailCheck(string email)
        {
            try
            {
                return _customer.CustomerEmailCheck(email);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool CusAdd(string pIdentityNumber, string pCustomerName, string pCustomerPhone, string pCustomerEmail,
                           bool pCustomerSex, out string account)
        {
            try
            {
                return _customer.CreateCustomer(pIdentityNumber, pCustomerName, pCustomerPhone, pCustomerEmail,
                                                pCustomerSex, out account);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool CusModify(int pId, string pIdentityNumber, string pCustomerName, string pCustomerPhone,
                              string pCustomerEmail, bool pCustomerSex)
        {
            try
            {
                return _customer.EditCustomer(pId, pIdentityNumber, pCustomerName, pCustomerPhone, pCustomerEmail,
                                              pCustomerSex);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion

        #region "Search Room"

        public List<vRoomInfo> SearchRoom(DateTime inDate, DateTime outDate, int roomTypeId, int minPrice, int maxPrice,
                                          bool view, bool bath, bool balcony)
        {
            try
            {
                return _search.SearchRoom(inDate, outDate, roomTypeId, minPrice, maxPrice, view, bath, balcony);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion
    }

    [ServiceContract]
    public interface IExternalService
    {
        #region "CUSTOMER Management"

        [OperationContract]
        bool CusAdd(string pIdentityNumber, string pCustomerName, string pCustomerPhone, string pCustomerEmail,
                      bool pCustomerSex, out string account);

        [OperationContract]
        bool CusModify(int pId, string pIdentityNumber, string pCustomerName, string pCustomerPhone,
                         string pCustomerEmail, bool pCustomerSex);

        [OperationContract]
        bool CusEmailCheck(string email);

        #endregion

        #region "Search Room"

        [OperationContract]
        List<vRoomInfo> SearchRoom(DateTime inDate, DateTime outDate, int roomTypeId, int minPrice, int maxPrice,
                                   bool view, bool bath, bool balcony);

        #endregion
    }
}